<template>
  <!-- 新增 搜索 -->
  <div>
    <!-- 表单 -->
    <TopFilter ref="form" :cols="3" :list="list" :collapse="false" @filterChange="formChange"></TopFilter>
    <!-- 表格 -->
    <FilterTable
      ref="table"
      :columns="columns"
      columnsRef="partPartInventoryPartInventoryComponentsFahuodan"
      :fetchapi="fetchApi"
      :params="fetchParams"
      height="200"
      selectionType="multiple"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="arr => (this.onChangeColumn = arr)"
      :onEnterEvent="onEnterEvent"
    >
      <!-- <template slot="controls">
        <el-button type="primary" @click="handleOnloneSearch">实时查询</el-button>
      </template> -->
    </FilterTable>
    <!-- 明细 -->
    <BaseDialog title="发运单明细" :visible.sync="isShowItems" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <TranslateItems :formdata="formdata" @close="isShowItems = false" />
    </BaseDialog>
    <div class="btnWrap">
      <el-button @click="$emit('cancel')">取 消</el-button>
      <el-button type="primary" @click="confirmBtnClick">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { state, mutations } from './../store';
import { queryPartInfo, queryPartStock } from '@/api/part/partOutbound/repairMaterials/index.js';
import { getAppId } from '@/assets/js/auth';
import { queryThreeTypeOrderDetail, partgetfourData } from '@/api/part/partInventory/partInventory/index.js';
import { notifyAction } from '@/utils';
import TranslateItems from './TranslateItems';
export default {
  name: 'fahuodan',
  components: {
    TranslateItems
  },
  props: ['orderType', 'orderNo'],
  data() {
    return {
      onChangeColumn: [],
      list: this.createList(),
      formdata: {},
      isShowItems: false,
      columns: this.createColumns(),
      fetchApi: partgetfourData,
      fetchParams: {
        orderNo: this.orderNo,
        orderType: this.orderType,
        xhrAbort: true
      }
    };
  },
  mounted() {
    if (getAppId() == 'beijing') {
      this.$refs.table.selectionType = 'multiple';
    }
    this.list.find(x => x.fieldName === 'orderNo').initialValue = this.orderNo;
  },
  methods: {
    createList() {
      return [
        {
          type: 'INPUT',
          label: '发运单号',
          fieldName: 'orderNo'
        },
        {
          type: 'RANGE_DATE',
          label: '签收日期',
          fieldName: 'begin|end',
          valueFormat: 'yyyy-MM-dd'
        }
      ];
    },
    createColumns() {
      return [
        {
          title: '序号',
          sorter: true,
          width: 70,
          dataIndex: 'xuhao',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          // sorter: true,
          dataIndex: 'column-action',
          minWidth: 100,
          render: props => {
            // <el-button onClick={() => this.deleteBtnClick(props)} type="text" disabled={this.operateBtnDisabled} size="mini">
            //   删除
            // </el-button>
            // <el-divider direction="vertical" />
            return (
              <div>
                <el-button onClick={() => this.showItems(props)} type="text" size="mini">
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '货运单号',
          // sorter: true,
          dataIndex: 'BSYSDH',
          filter: true,
          filterType: 'input'
        },
        {
          title: '货运日期',
          sorter: true,
          dataIndex: 'BSFYRQ',
          dateFormat: 'yyyy-MM-dd',
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '发货总数量',
          sorter: true,
          dataIndex: 'orderCount',
          filter: true,
          filterType: 'number'
        },
        {
          title: '签收总数量',
          sorter: true,
          dataIndex: 'orderArrived',
          filter: true,
          filterType: 'number'
        },
        {
          title: '签收日期',
          sorter: true,
          dataIndex: 'BSSCRQ',
          dateFormat: 'yyyy-MM-dd',
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '配件总金额',
          sorter: true,
          dataIndex: 'orderAmount',
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '备注',
          sorter: true,
          dataIndex: 'XTCSBZ'
        }
        // {
        //   title: '供应商代码',
        //   // sorter: true,
        //   dataIndex: 'SUPPLIER_ID',
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '供应商名称',
        //   // sorter: true,
        //   dataIndex: 'SUPPLIER_NAME',
        //   filter: true,
        //   filterType: 'input'
        // },

        // {
        //   title: '发货中转库',
        //   // sorter: true,
        //   dataIndex: 'mei11'
        // },
        // {
        //   title: '采购类型',
        //   // sorter: true,
        //   dataIndex: 'mei12'
        // }
      ];
    },
    showItems(val) {
      console.log(val, 'val::::');
      this.formdata = val.row;
      this.isShowItems = true;
    },
    // 点击搜索或者重置
    FormPanelSeacher() {
      this.$refs.form.SUBMIT_FORM();
    },

    formChange(val) {
      this.fetchParams.xhrAbort = true;
      this.fetchParams = Object.assign({}, this.fetchParams, val, { xhrAbort: false, online: 0 });
      // this.queryThreeTypeOrderDetail(p)
    },
    async queryThreeTypeOrderDetail() {
      let x = {};
      x.orderType = this.orderType;
      x.orderNo = 'bjqs002';
      const res = await queryThreeTypeOrderDetail(x);
    },
    // 获取表单数据
    async partgetfourData() {
      let params = {};
      params.orderType = this.orderType;
      params.orderNo = '';
      const res = await partgetfourData(params);
    },
    async onEnterEvent(row) {
      // 双击选中  整合配件信息
      console.log('onEnterEvent', row);
      this.$emit('dblclickPartInfo', Object.assign({}, row));
      return;
      const res = await queryPartStock({
        partNo: row['PART_NO'],
        storageCode: row['STORAGE_CODE']
      });
      if (res.resultCode != 200) {
        console.log('查询配件 失败', res);
        return;
      }
      const part = res.data.rows[0];
      // 整合配件信息
      // const partInfo = Object.assign({}, row, part);
      const partInfo = Object.assign({}, part);
      console.log('整合后的配件信息', partInfo);
      this.$parent.setPartInfo(partInfo);
    },
    // 点击实时查询
    async handleOnloneSearch() {
      let formData = await this.$refs.form.GET_FORM_DATA();
      if (!formData[1].orderNo) {
        return notifyAction('实时查询发运单号不能为空', 'warning');
      }
      this.fetchParams.xhrAbort = true;
      this.fetchParams = Object.assign(this.fetchParams, {
        ...formData[1],
        online: 1,
        xhrAbort: false
      });
    },
    // 确定
    confirmBtnClick() {
      this.$emit('confirm', this.onChangeColumn);
    }
  }
};
</script>

<style scoped>
.btnWrap {
  position: absolute;
  left: 0px;
  bottom: 0px;
  right: 0px;
  z-index: 9;
  border-top: 1px solid rgb(233, 233, 233);
  padding: 10px 20px;
  background: rgb(255, 255, 255);
  text-align: right;
}
</style>
